<template>
  <div class="right-section" style="display: block">
    <div class="video-list-title">相关视频</div>
    <div class="video-list-container">
      <ul id="videos">
        <li class="media" :class="(index === 0 ? 'active' : '')" v-for="(video, index) of VideoList" :key="video.id">
          <div class="media-left">
            <div class="top-info-thumb">
              <a  :href="`/preview?videoId=${video.id}&mId=${video.mId}`" style="color: inherit; text-decoration: none;cursor: pointer;">
                <img :src="video.iSrc" class="media-boject" alt="" />
                <div class="time">{{ formatTime(video.len)}}</div>
              </a>
            </div>
          </div>
          <div class="media-body media-middle">
            <div class="video-title">
              <a  :href="`/preview?videoId=${video.id}&mId=${video.mId}`" style="color: inherit; text-decoration: none;cursor: pointer;">{{video.des}}</a>
            </div>
            <div class="video-play-count">{{numberFormat(video.watchNum).value}}{{numberFormat(video.watchNum).unit}}</div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import {formatSecondsToMinutes} from '@/utils'
export default {
  name: 'TtmsList',
  props: ['videoId', 'mId'],
  data () {
    return {
      flag: true
    }
  },

  mounted () {
    console.log(this.mId)
    console.log(this.videoId)
    this.$store.dispatch('video/getVideos', {
      mId: this.mId,
      videoId: this.videoId
    })
  },
  computed: {
    ...mapState('video', ['VideoList']),
  },
  methods: {
    formatTime(time){
      return formatSecondsToMinutes(time)
    },
    numberFormat (value) {
      const param = {}
      const k = 10000
      const sizes = ['', '万', '亿', '万亿']
      let i
      if (value < k) {
        param.value = value
        param.unit = ''
      } else {
        i = Math.floor(Math.log(value) / Math.log(k))

        param.value = ((value / Math.pow(k, i))).toFixed(2)
        param.unit = sizes[i]
      }
      return param
    }
  }
}
</script>

<style lang="scss" scoped>
.right-section .video-play-count {
  margin-top: 5px;
  font-size: 12px;
}

.video-play-count:before {
  content: "";
  display: inline-block;
  margin-right: 5px;
  width: 0;
  height: 0;
  border-width: 5px 0 5px 8px;
  border-style: solid;
  border-color: transparent transparent transparent #666;
}

.media-body,
.media-left,
.media-right {
  display: table-cell;
  vertical-align: top;
}

.media-body {
  width: 10000px;
}

div {
  display: block;
}

.right-section {
  /*display: none;*/
  float: right;
  background: #1a1b1e;
  background: rgba(0, 0, 0, 0.3);
  padding: 12px 5px 15px 20px;
  width: 425px;
  line-height: 1.5;
}

.right-section .video-list-title {
  font-size: 14px;
  margin-bottom: 10px;
}

.right-section .video-list-container {
  height: 470px;
  overflow: auto;
}

ul {
  display: block;
  margin-block-start: 1em;
  margin-block-end: 1em;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
  padding-inline-start: 40px;
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.right-section .media.active {
  color: #ef4238;
}

.right-section .media {
  margin-top: 0;
  height: 94px;
  overflow: hidden;
}

.right-section .media-left {
  width: 142px;
  height: 82px;
  position: relative;
}
.media-left,
.media > .pull-left {
  padding-right: 10px;
}

.right-section .media.active .media-left img {
  border-color: #ef4238;
}

.right-section .media-left img {
  width: 138px;
  height: 78px;
  border: 2px solid transparent;
}

.right-section .media-left .time {
  border-radius: 2px;
  display: block;
  height: 18px;
  padding: 0 5px;
  line-height: 18px;
  text-align: center;
  background: #000;
  filter: alpha(opacity=70);
  background: rgba(0, 0, 0, 0.7);
  position: absolute;
  left: 6px;
  bottom: 11px;
  font-size: 12px;
  color: #fff;
}

.media-middle {
  vertical-align: middle;
}

.right-section .video-title {
  display: block;
  width: 250px;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
